const { query } = require("../db/query")
module.exports = {
  // 获取论坛全部数据
  getAllForumList: async () => {
    // 调用query发送sql语句到mysql进行注册用户
    return await query("SELECT * FROM forum")
  },
  // 获取论坛数据
  getForumList: async (current, pagesize) => {
    const currentSize = (current - 1) * pagesize;
    // 调用query发送sql语句到mysql进行注册用户
    return await query("select * from forum group by createtime desc,posts_id desc limit ?,?;", [currentSize, parseInt(pagesize)])
  },
  // 通过id获取论坛
  getForumOfId: async (posts_id) => {
    // 调用query发送sql语句到mysql进行注册用户
    return await query("select * from forum where posts_id =?", [posts_id])
  },
  // 获取论坛评论列表
  getForumComment: async (posts_id) => {
    // 调用query发送sql语句到mysql进行注册用户
    return await query("select * from onecomment where posts_id =?", [posts_id])
  },
  // 获取论坛评论列表
  getForumCommentPag: async (posts_id, current, pagesize) => {
    const currentSize = (current - 1) * pagesize;
    // 调用query发送sql语句到mysql进行注册用户
    return await query("select * from onecomment where posts_id =? limit ?,?;", [posts_id, currentSize, parseInt(pagesize)])
  },
  // 发表评论
  publishComment: async (posts_id, user_id, user_name, user_avatar, content, createtime) => {
    // 调用query发送sql语句到mysql进行注册用户
    return await query("insert into onecomment(posts_id, user_id, user_name, user_avatar, content, createtime) values(?,?,?,?,?,?)", [posts_id, user_id, user_name, user_avatar, content, createtime])
  },
  // 发布论坛
  releaseForum: async (user_id, user_name, user_avatar, title, details_content, brief_content, createtime) => {
    // 调用query发送sql语句到mysql进行注册用户
    return await query("insert into forum(user_id, user_name, user_avatar, title, details_content, brief_content, createtime) values(?,?,?,?,?,?,?)", [user_id, user_name, user_avatar, title, details_content, brief_content, createtime])
  },
}